package com.kmproject.haifu.mvp.ui.bis.recharge;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jess.arms.mvp.IView;
import com.jess.arms.widget.CustomPopupWindow;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.mvp.model.entity.beans.ExchangeRateBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberPayResultBean;
import com.kmproject.haifu.mvp.ui.adapter.MemberCenterPayWayAdapter;

import java.util.List;

public interface IViewRecharge extends IView {
    void getPayWaySuccess(List<HousePayWayBean> housePayWayBeans);

    void getExchangeRateSuccess(ExchangeRateBean exchangeRateBean);

    void paySuccess();

    void rechargeCallCharge4AliPaySuccess(String result);

    void rechargeCallCharge4WxSuccess(MemberPayResultBean result);

    /**
     * @param housePayWayBeans   支付方式列表
     * @param exchangeRateBean   汇率对象
     * @param clickBack          支付方式选择回调
     * @param confirmPayListener 确认支付按钮点击监听器
     *                           支付弹框
     */
    default CustomPopupWindow payPopupWindow(Activity activity, View mParentView, List<HousePayWayBean> housePayWayBeans, ExchangeRateBean exchangeRateBean,
                                             MemberCenterPayWayAdapter.ItemClickBack clickBack, View.OnClickListener confirmPayListener, View.OnClickListener closeListener) {
        if (exchangeRateBean == null || housePayWayBeans == null) {
            return null;
        }

        return new CustomPopupWindow.Builder().parentView(mParentView).contentView(CustomPopupWindow.inflateView(activity, R.layout.popuwindow_pay)).backgroundDrawable(activity.getResources().getDrawable(R.drawable.button_white_bg))
                .animationStyle(R.style.mypopwindow_anim_style).customListener(contentView -> {
                    LinearLayout popuwindowPayClose = (LinearLayout) contentView.findViewById(R.id.popuwindow_pay_close);
                    TextView popuwindowPayJrhl = (TextView) contentView.findViewById(R.id.popuwindow_pay_jrhl);
                    TextView popuwindowPayDqhlyh = (TextView) contentView.findViewById(R.id.popuwindow_pay_dqhlyh);
                    TextView popuwindowPayDqhl = (TextView) contentView.findViewById(R.id.popuwindow_pay_dqhl);
                    TextView popuwindow_pay_money = (TextView) contentView.findViewById(R.id.popuwindow_pay_money);
                    popuwindowPayJrhl.setText("1:" + exchangeRateBean.getCnyExchangeRate());
                    if (exchangeRateBean.getRebate() != null && !TextUtils.isEmpty(exchangeRateBean.getRebate()) && Double.parseDouble(exchangeRateBean.getRebate()) > 0 && Double.parseDouble(exchangeRateBean.getRebate()) < 10) {
                        popuwindowPayDqhlyh.setText("当前汇率(已优惠" + exchangeRateBean.getRebate() + "折)");
                    } else {
                        //没有优惠
                        popuwindowPayDqhlyh.setVisibility(View.GONE);
                        popuwindowPayDqhl.setVisibility(View.GONE);
                    }

                    popuwindowPayDqhl.setText("1:" + exchangeRateBean.getCnyDiscountExchangeRate());
                    popuwindow_pay_money.setText("￥ " + AppUtil.getShowMenoy(exchangeRateBean.getDiscountAmount()));
                    RecyclerView popuwindow_pay_RecyclerView = (RecyclerView) contentView.findViewById(R.id.popuwindow_pay_RecyclerView);
                    popuwindow_pay_RecyclerView.setLayoutManager(new LinearLayoutManager(activity));
                    MemberCenterPayWayAdapter memberCenterPayWayAdapter = new MemberCenterPayWayAdapter(housePayWayBeans, clickBack);
                    popuwindow_pay_RecyclerView.setAdapter(memberCenterPayWayAdapter);

                    TextView popuwindowPaySure = (TextView) contentView.findViewById(R.id.popuwindow_pay_sure);
                    popuwindowPaySure.setText("确认支付 ￥ " + exchangeRateBean.getDiscountAmount());
                    popuwindowPaySure.setOnClickListener(confirmPayListener);
                    popuwindowPayClose.setOnClickListener(closeListener);
                }).isWrap(true).isHaveBackGround(true).isShowBottom(true).build();
    }
}
